<%-- 
Document   : aar
Created on : Apr 1, 2010, 12:30:25 PM
Author     : Clarence
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<%@ include file="common.jsp" %>
<%
            ArrayList<Player> players = PlayerDAO.retrieveAllPlayersOrderByWinner();
            int total_number_of_turns = AnalyticEmployeeUtilisationDAO.getMaxTurn();
%>
<html>
    <c:set var="title" value="MIC Tycoon ~ Admin"/>
    <%@ include file="htmlheader.jsp" %>
    <body>

        <div id="resolution">

            <div class="content" id="admin_content">
                <div id="admin">
                    <% for (int i = 0; i < players.size(); i++) {%>
                    <% Player player = players.get(i);%>



                    <table cellpadding="8">
                        <tr>
                            <td style="font-weight: bold;" colspan="<%=total_number_of_turns + 2%>">
                                <%= player.getPlayer_name()%> - <%= player.getCompany_name()%> ($<%= player.getBalance()%>)
                            </td>
                        </tr>

                        <tr style="font-weight: bold;">
                            <td>
                                Turn
                            </td>
                            <% for (int j = 0; j < total_number_of_turns; j++) {%>

                            <td>
                                Turn<BR><%= j + 1%>
                            </td>
                            <% }%>

                            <td>
                                Average
                            </td>
                        </tr>

                        <tr>
                            <td>
                                Employee Utilisation
                            </td>
                            <% double avg_employee_utilisation = 0;%>
                            <% for (int j = 0; j < total_number_of_turns; j++) {%>
                            <% int turn = j + 1;%>
                            <%
                                 double employee_utilisation = AnalyticEmployeeUtilisationDAO.getEmployeeUtilisation(player.getPlayer_id(), turn) * 100;
                                 avg_employee_utilisation += employee_utilisation;
                            %>

                            <td>
                                <% if (employee_utilisation >= 0) {%>
                                <%= (int) employee_utilisation%>%
                                <% } else {%>
                                N/A
                                <% }%>
                            </td>
                            <% }%>
                            <td>
                                <% avg_employee_utilisation = avg_employee_utilisation / total_number_of_turns;%>
                                <% if (avg_employee_utilisation >= 0) {%>
                                <%= (int) avg_employee_utilisation%>%
                                <% } else {%>
                                N/A
                                <% }%>
                            </td>
                        </tr>


                        <tr>
                            <td>
                                Projects Bidded <BR>(Successfully)
                            </td>
                            <%
                                 int all_projectbid = 0;
                                 int all_projectbidsuccess = 0;
                            %>
                            <% for (int j = 0; j < total_number_of_turns; j++) {%>
                            <% int turn = j + 1;%>
                            <%
                                 all_projectbid += AnalyticProjectDAO.getProjectBidCount(player.getPlayer_id(), turn);
                                 all_projectbidsuccess += AnalyticProjectDAO.getSuccessfulProjectBidCount(player.getPlayer_id(), turn);


                            %>
                            <td>
                                <%= AnalyticProjectDAO.getProjectBidCount(player.getPlayer_id(), turn)%>
                                <BR>
                                (<%= AnalyticProjectDAO.getSuccessfulProjectBidCount(player.getPlayer_id(), turn)%>)
                            </td>
                            <% }%>
                            <td>
                                <%= all_projectbid%>
                                <BR>
                                (<%= all_projectbidsuccess%>)
                            </td>
                        </tr>


                        <tr>
                            <td>
                                Outsource Project Taken
                            </td>
                            <%
                                 int all_os_project_taken = 0;
                            %>
                            <% for (int j = 0; j < total_number_of_turns; j++) {%>
                            <% int turn = j + 1;%>
                            <% all_os_project_taken += AnalyticProjectDAO.getOSProjectPurchased(player.getPlayer_id(), turn);%>
                            <td>
                                <%= AnalyticProjectDAO.getOSProjectPurchased(player.getPlayer_id(), turn)%>
                            </td>
                            <% }%>
                            <td>
                                <%= all_os_project_taken%>
                            </td>
                        </tr>

                        <tr>
                            <td>
                                Projects Submitted
                                <BR>
                                (On Time / Late)
                            </td>
                            <%
                                 int all_project_submitted = 0;
                                 int all_project_submitted_on_time = 0;
                                 int all_project_submitted_late = 0;
                            %>
                            <% for (int j = 0; j < total_number_of_turns; j++) {%>
                            <% int turn = j + 1;%>
                            <%
                                 all_project_submitted += AnalyticProjectDAO.getProjectSubmittedCount(player.getPlayer_id(), turn);
                                 all_project_submitted_on_time += AnalyticProjectDAO.getProjectSubmittedOnTimeCount(player.getPlayer_id(), turn);
                                 all_project_submitted_late += AnalyticProjectDAO.getProjectSubmittedLateCount(player.getPlayer_id(), turn);
                            %>
                            <td>
                                <%= AnalyticProjectDAO.getProjectSubmittedCount(player.getPlayer_id(), turn)%>
                                <BR>
                                (<%= AnalyticProjectDAO.getProjectSubmittedOnTimeCount(player.getPlayer_id(), turn)%> / <%= AnalyticProjectDAO.getProjectSubmittedLateCount(player.getPlayer_id(), turn)%>)
                            </td>
                            <% }%>
                            <td>
                                <%= all_project_submitted%>
                                <BR>
                                (<%= all_project_submitted_on_time%> / <%= all_project_submitted_late%>)
                            </td>
                        </tr>




                        <tr>
                            <td>
                                Outsource Projects Submitted <BR>(On Time / Late)
                            </td>
                            <%
                                 int all_os_project_submitted = 0;
                                 int all_os_project_submitted_on_time = 0;
                                 int all_os_project_submitted_late = 0;
                            %>
                            <% for (int j = 0; j < total_number_of_turns; j++) {%>
                            <% int turn = j + 1;%>
                            <%
                                 all_os_project_submitted += AnalyticProjectDAO.getOSProjectSubmittedCount(player.getPlayer_id(), turn);
                                 all_os_project_submitted_on_time += AnalyticProjectDAO.getOSProjectSubmittedOnTimeCount(player.getPlayer_id(), turn);
                                 all_os_project_submitted_late += AnalyticProjectDAO.getOSProjectSubmittedLateCount(player.getPlayer_id(), turn);
                            %>
                            <td>
                                <%= AnalyticProjectDAO.getOSProjectSubmittedCount(player.getPlayer_id(), turn)%>
                                <BR>
                                (<%= AnalyticProjectDAO.getOSProjectSubmittedOnTimeCount(player.getPlayer_id(), turn)%> / <%= AnalyticProjectDAO.getOSProjectSubmittedLateCount(player.getPlayer_id(), turn)%>)
                            </td>
                            <% }%>
                            <td>
                                <%= all_os_project_submitted%>
                                <BR>
                                (<%= all_os_project_submitted_on_time%> / <%= all_os_project_submitted_late%>)
                            </td>
                        </tr>



                        <tr>
                            <td>
                                Project Bidding Margin
                            </td>
                            <%
                                 double avg_project_bid_margin = 0.0;
                                 int turn_with_bids = 0;
                            %>
                            <% for (int j = 0; j < total_number_of_turns; j++) {%>
                            <% int turn = j + 1;%>

                            <%
                                 double project_bid_margin = Analytic.getProjectBidMargin(player.getPlayer_id(), turn);

                                 avg_project_bid_margin += project_bid_margin;
                                 if (project_bid_margin > 0) {
                                     turn_with_bids ++;
                                 }
                            %>
                            <td>
                                <%= (int) (Analytic.getProjectBidMargin(player.getPlayer_id(), turn) * 100)%>%
                            </td>
                            <% }%>
                            <td>
                                <%= (int) ((avg_project_bid_margin / turn_with_bids) * 100)%>%
                            </td>
                        </tr>
                    </table>
                    <BR><BR>


                    <% }%>
                </div>
            </div>
        </div>

    </body>
</html>
